﻿using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading;

namespace Rbac.Project.Test
{
    internal class Program
    {
        public class record
        {
            public int num { get; set; }
        }

        static void Main(string[] args)
        {
            var a = Proxy("abc");
        }

        public void Recurtion(string s, int i)
        {
            
        }

        /// <summary>
        /// 目标方法--自己写的方法
        /// </summary>
        /// <param name="strings"></param>
        /// <returns></returns>
        /// [Proxy]
        public static string Test(params string[] strings)
        {
            return string.Join("--", strings);
        }

        /// <summary>
        /// 代理方法--过滤器
        /// </summary>
        /// <returns></returns>
        public static string Proxy(params string[] strings)
        {
            //执行之前
            var a = 1;

            //调用结果
            var b = Test(strings);
            
            //执行之后
            var c = 2;

            //return 出去
            return b;
        }

        static List<ResposeEnum> GetMenuTree(List<Enum> list, int pid)
        {
            List<ResposeEnum> tree = new List<ResposeEnum>();
            List<Enum> children = list.Where(m => m.pid == pid).ToList();  //从第一级根节点开始
            if (children.Count > 0)
            {
                for (var i = 0; i < children.Count; i++)
                {
                    var child = GetMenuTree(list, children[i].id);
                    ResposeEnum itemMenu = new ResposeEnum()
                    {
                        id = children[i].id,
                        Name = children[i].Name,
                        pid = children[i].pid,
                        Childen = child
                    };
                    tree.Add(itemMenu);
                }
            }
            return tree;
        }





        public static List<ResposeEnum> Recurtion(List<Enum> list,int pid)
        {
            List<ResposeEnum> tree = new List<ResposeEnum>();
            var children = list.Where(m => m.pid == pid).ToList();
            if(children.Count > 0)
            {
                foreach (var item in children)
                {
                    ResposeEnum node = new ResposeEnum()
                    {
                        pid = item.pid,
                        id = item.id,
                        Name = item.Name,
                        Childen = Recurtion(list, item.id)
                    };
                    tree.Add(node);
                }
            }
            return tree;
        }
    }

    

    public class Enum
    {
        public int id { get; set; }
        public string Name { get; set; }
        public int pid { get; set; }
    }

    public class ResposeEnum
    {
        public int id { get; set; }
        public string Name { get; set; }
        public int pid { get; set; }
        public List<ResposeEnum> Childen { get; set; }
    }

    public class ApplicationDbContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer(@"Data Source=.;Initial Catalog=HotelNet;Integrated Security=True");
        }

        public DbSet<sys_log_op> sys_log_op { get; set; }
    }

    [Table("sys_log_op")]
    public class sys_log_op
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Location { get; set; }
        public string Url { get; set; }
    }
}
